package modelLayer;

import java.util.ArrayList;

/**
 * Write a description of class PersonContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PersonContainer
{
    // instance variables - replace the example below with your own
    private ArrayList<Person> personList;
    private static PersonContainer instance;
    
    /**
     * Constructor for objects of class PersonContainer
     */
    // Singleton => private constructor
    private PersonContainer()
    {
        // initialise instance variables
        personList = new ArrayList<Person>();
    }
    
    //Singleton getInstance() method
    public static PersonContainer getInstance() 
    {
        if(instance == null) 
        {
            instance = new PersonContainer();
        }
        return instance;
    }
    
    public void addPerson(Person person)
    {
        if(!personList.contains(person)) {
            personList.add(person);
        }
    }
    
    public Person getPerson(String cpr) 
    {
        Person returnPerson = null;
        for(Person person : personList)
        {
            if(person.getCpr().equals(cpr)) 
            {
                returnPerson = person;
            }
        }
        return returnPerson;
    }
    
    public void deletePerson(Person person) {
        personList.remove(person);
    }
          
}
